package pre.bookcloud.java21.menu2;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/** 学生数据模型类 */
public class Student {
  private String name; // 学生姓名
  private String stu_no; // 学生编号
  private String sign_status; // 签到状态：signed（已签到）、absent（缺席）
  private String sign_date; // 签到日期
  private String gen_date; // 表单生成日期

  // 构造函数
  public Student() {}

  public Student(String name, String stu_no) {
    this.name = name;
    this.stu_no = stu_no;
    this.sign_status = "absent";
    this.gen_date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  }

  // Getter和Setter方法
  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getStu_no() {
    return stu_no;
  }

  public void setStu_no(String stu_no) {
    this.stu_no = stu_no;
  }

  public String getSign_status() {
    return sign_status;
  }

  public void setSign_status(String sign_status) {
    this.sign_status = sign_status;
    if ("signed".equals(sign_status)) {
      this.sign_date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }
  }

  public String getSign_date() {
    return sign_date;
  }

  public void setSign_date(String sign_date) {
    this.sign_date = sign_date;
  }

  public String getGen_date() {
    return gen_date;
  }

  public void setGen_date(String gen_date) {
    this.gen_date = gen_date;
  }

  /** 签到方法 */
  public void signIn() {
    this.sign_status = "signed";
    this.sign_date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
  }

  /** 取消签到 */
  public void cancelSign() {
    this.sign_status = "absent";
    this.sign_date = null;
  }

  @Override
  public String toString() {
    return "Student{"
        + "name='"
        + name
        + '\''
        + ", stu_no='"
        + stu_no
        + '\''
        + ", sign_status='"
        + sign_status
        + '\''
        + ", sign_date='"
        + sign_date
        + '\''
        + ", gen_date='"
        + gen_date
        + '\''
        + '}';
  }
}
